package cn.faifai.tagapi.dto;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
public class PageQuery<T>{
    /**
     * 分页大小
     */
    private Integer pageSize;

    /**
     * 当前页数
     */
    private Integer pageNum;

    private List<T> contents;

    private Long total;
    private int totalPages;

    public PageQuery() {
    }

    public PageQuery(Integer pageNum, Integer pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public Integer getJPAPageNum(){
        if (pageNum < 1) {
            throw new IllegalArgumentException("页码必须大于0");
        }
        return pageNum-1;
    }
}
